﻿using BasehInfoManagerModel;
using BasehInfoManagerViewModel;
using BasehInfoManagerViewModel.Common;
using BaseInfoManagerBll;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace zy_11._10.Controllers
{
    
    public class AdminUserManagerController : MyBaseController
    {

        //依赖注入
        private AdminUserBll _adminUserBll;
        public AdminUserManagerController(AdminUserBll adminUserBll)
        {
            _adminUserBll = adminUserBll;
        }


        //显示
        [HttpPost]
        public ResultModel<PagerResult<AdminUser>> SearchPage(SearchModel sm)
        {
            try
            {
                var data = _adminUserBll.SearchPage(sm);
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<PagerResult<AdminUser>>(ex);
            }
        }

        //用户添加
        [HttpPost]
        public ResultModel<bool> AdminUserAdd(AdminUserView view)
        {
            try
            {
                view.creator_date = DateTime.Now;
                view.creator_name = "哈哈";
                var data = _adminUserBll.AdminUserAdd(view);
                return MyOk(data);

            }
            catch (Exception ex)
            {
                return MyError<bool>(ex);
            }
        }

        //查询用户名
        [HttpGet]
        public ResultModel<bool> VAdmminUserName(string userName)
        {
            try
            {
                var data = _adminUserBll.VAdmminUserName(userName);
                return MyOk(data);

            }
            catch (Exception ex)
            {
                return MyError<bool>(ex);
            }
        }

        //修改
        [HttpPost]
        public ResultModel<bool> AdminUserUpdate(AdminUserView view)
        {
            try
            {
                view.modifi_date = DateTime.Now;
                view.modifi_name = "嘻嘻";
                var data = _adminUserBll.AdminUserUpdate(view);
                return MyOk(data);

            }
            catch (Exception ex)
            {
                return MyError<bool>(ex);
            }
        }

        //查询用户模型类
        [HttpGet]
        public ResultModel<AdminUserView> GetAdminUserViewByUserName(string userName)
        {
            try
            {
                var data = _adminUserBll.GetAdminUserViewByUserName(userName);
                if (data == null)
                {
                    return MyFail<AdminUserView>("没有获取对应的用户");
                }
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<AdminUserView>(ex);
            }
        }


        //修改密码
        [HttpPost]
        public IActionResult AdminUserPwdUpdate(string userName, string Npwd)
        {
            return Ok(_adminUserBll.AdminUserPwdUpdate(userName, Npwd));
        }





    }
}
